package ios.di.logviewer.ui;



import ios.di.logviewer.data.LogEntry;
import ios.di.logviewer.data.PageProcessor;
import ios.di.logviewer.util.DateUtil;

import java.util.List;
import java.util.Vector;

import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;


import jpcap.packet.Packet;

/**
 * 日志信息表格的数据结构
 * @author LuoHouQi
 *
 */
	
	public class DataTableModel extends AbstractTableModel
	{
		List<LogEntry> logs;
		
		String[] columnNames = {"操作描述","成功","业务类型","业务数据日期","业务信息","供应商id","上传/下载时间","用户","详细信息"};
		@Override
		public String getColumnName(int column) {
			if(column>=0&&column<columnNames.length)
				return columnNames[column];
			else return "Error";
		}
			

		@Override
		public int getColumnCount() {
			// TODO Auto-generated method stub
			return columnNames.length;
		}

		@Override
		public int getRowCount() {
			if (logs==null)
				return 0;
			else return logs.size();
		}

		@Override
		public Object getValueAt(int rowIndex, int columnIndex) {
			if(rowIndex> this.logs.size())
				return null;
			switch(columnIndex)
			{
			case 0: 
			{
				return  this.logs.get(rowIndex).getOperation();
			}
			case 1: 
			{
				boolean success = this.logs.get(rowIndex).isIssuccess();
				if(success)
					return "是";
				else return "否";
			}
			case 2:
				return this.logs.get(rowIndex).getBussnessType();
			case 3:
			{
				String date =  DateUtil.getDateUtil(DateUtil.PATTERN_1).convertToString(  this.logs.get(rowIndex).getBussnessDate());
				if(date ==null)
					return "Error";
				else return date;
			}
			case 4:
				return this.logs.get(rowIndex).getBussnessInfo();
			case 5:
				return this.logs.get(rowIndex).getVendorID();
			case 6:
			{
				String date =  DateUtil.getDateUtil(DateUtil.PATTERN_1).convertToString( this.logs.get(rowIndex).getHappenDate());
				if(date ==null)
					return "Error";
				else return date;
			}
			case 7:
				return this.logs.get(rowIndex).getOperator();
			case 8:
				return this.logs.get(rowIndex).getDetails();
			}
			
				return "Error";
			
		}


	


		public void setLogs(List<LogEntry> logs) {
			this.logs = logs;
		}


		
		
	}

